controls:WebBrowserUtility.Body="{Binding MessageBuilder}"/>
I'm using this class to enable binding to the Body of the WebBrowser control
public static class WebBrowserUtility
{
public static readonly DependencyProperty BodyProperty =
DependencyProperty.RegisterAttached("Body", typeof(string), typeof(WebBrowserUtility), new PropertyMetadata(OnBodyChanged));
public static string GetBody(DependencyObject dependencyObject)
{
return (string)dependencyObject.GetValue(BodyProperty);
}
public static void SetBody(DependencyObject dependencyObject, string body)
{
dependencyObject.SetValue(BodyProperty, body);
}
private static void OnBodyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var webBrowser = d as WebBrowser;
if (!string.IsNullOrWhiteSpace(e.NewValue as string) && webBrowser != null)
{
if (Application.Current.MainWindow != null && !DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow))
{
webBrowser.NavigateToString((string)e.NewValue);
}
}
}
}
That's my WebBrowser, I'm binding it to a StringBuilder property on the ViewModel. How can I get the WebBrowser control to scroll to the end?
Vijay Shukla
19-Jul-2013If you cast the WebBrowser's Document property to a mshtml.HTMLDocument, then you can scroll to a specific position in the page (or the bottom by using the largest value possible):
var html = webBrowser.Document as mshtml.HTMLDocument;
html.parentWindow.scroll(0, int.MaxValue);
Note you have to add a reference to Microsoft.mshtml in your project.